﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CYTS.Aoyou.Framework.Utility
{
    public class SqlMapHelper
    {

        public static string GetSqlMappingString(string sqlBusinesName,string sqlName=null)  
        {
            SqlMapConfig unit = SqlMapCache.GetSqlMapConfig(sqlBusinesName);
            string returnSqlStr = string.Empty;
            if(unit!=null)
            {
                returnSqlStr = AnalyseSqlMapContent(unit,sqlName);
            }

            return returnSqlStr;
        }

        private static string AnalyseSqlMapContent(SqlMapConfig config, string sqlName=null) 
        {
            string analyseSql = string.Empty;
            if(config.SqlMapConfigurationList!=null)
            {
                if(sqlName!=null)
                {
                    SqlMapDetail detail=config.SqlMapConfigurationList.Where(p => p.SqlName == sqlName).FirstOrDefault();
                    analyseSql = detail!=null?detail.OriginalSqlString:string.Empty;
                }
            }

            return analyseSql;
        }
    }
}


